package com.yjz.zpay.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import de.robv.android.xposed.XSharedPreferences;

/**
 * SharedPreferences 工具类
 * @author yjz
 * created at 2019/1/10 下午2:06
 */

public class SpUtils {

	private static final String SHARED_PATH = "com.yjz.zpay";
	private static final String SHARED_PATH_XP = "com.yjz.zpay_preferences";

	public static SharedPreferences getDefaultSharedPreferences(Context context) {
		return context.getSharedPreferences(SHARED_PATH, Context.MODE_PRIVATE);
	}

	public static SharedPreferences getXpSharedPreferences(Context context) {
		return context.getSharedPreferences(SHARED_PATH_XP, Context.MODE_PRIVATE);
	}

	public static void putInt(Context context,String key, int value) {
		SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
		Editor edit = sharedPreferences.edit();
		edit.putInt(key, value);
		edit.commit();
	}

	public static int getInt(Context context,String key) {
		SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
		return sharedPreferences.getInt(key, 0);
	}
	
	public static void putString(Context context,String key, String value) {
		SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
		Editor edit = sharedPreferences.edit();
		edit.putString(key, value);
		edit.commit();
	}

	public static String getString(Context context,String key) {
		SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
		return sharedPreferences.getString(key,null);
	}
	
	public static void putBoolean(Context context,String key, boolean value) {
		SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
		Editor edit = sharedPreferences.edit();
		edit.putBoolean(key, value);
		edit.commit();
	}

	public static boolean getBoolean(Context context,String key,boolean defValue) {
		SharedPreferences sharedPreferences = getDefaultSharedPreferences(context);
		return sharedPreferences.getBoolean(key,defValue);
	}


	///////////////////////////////////////////////////////////////////////////
	// xp
	///////////////////////////////////////////////////////////////////////////
	public static String getStringXp(String key,String def) {
		XSharedPreferences sharedPreferences = new XSharedPreferences(SHARED_PATH);
		return sharedPreferences.getString(key, def);
	}

	public static void putStringXp(Context context, String key, String value) {
		SharedPreferences sharedPreferences = getXpSharedPreferences(context);
		Editor edit = sharedPreferences.edit();
		edit.putString(key, value);
		edit.commit();
	}

}
